/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__is_surround_by_parenthesis.c                    */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/15 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../../src/module/oracle/config.h"
#include <oracle/ora_core.h>
#include <oracle/comm/ora_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

int __is_surround_by_parenthesis(char *p_data);

static void __case1(void)
{
    int i_ret = 0;
    char *p_data = NULL;

    i_ret = __is_surround_by_parenthesis(p_data);
    
    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
}

static void __case2(void)
{
    int i_ret = 0;
    char *p_data = NULL;
    
    p_data = (char *) frmalloc(strlen("SID=orc1") + 1);
    snprintf(p_data, strlen("SID=orc1") + 1, "%s", "SID=orc1");

    i_ret = __is_surround_by_parenthesis(p_data);
    
    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    
    frfree(p_data);
}

static void __case3(void)
{
    int i_ret = 0;
    char *p_data = NULL;
    
    p_data = (char *) frmalloc(strlen("(SID=orc1)") + 1);
    snprintf(p_data, strlen("(SID=orc1)") + 1, "%s", "(SID=orc1)");

    i_ret = __is_surround_by_parenthesis(p_data);
    
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    
    frfree(p_data);
}

int add_suite__is_surround_by_parenthesis(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __is_surround_by_parenthesis()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
